package fr.xebia.data;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * 
 */
@Entity
@Table(name = "contract")
public class Contract implements Serializable {

	private static final long serialVersionUID = 1L;

	private Long id;
	private String comment;
	private Long status;
	private Long type;
	private Client client;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * Gets the comment
	 * 
	 * @returns the comment
	 */
	@Column(name = "COMMENT")
	public String getComment() {
		return this.comment;
	}

	/**
	 * Sets the comment
	 * 
	 * @param the
	 *            comment
	 */
	public void setComment(String pComment) {
		this.comment = pComment;
	}

	/**
	 * Gets the status
	 * 
	 * @returns the status
	 */
	@Column(name = "STATUS")
	public Long getStatus() {
		return this.status;
	}

	/**
	 * Sets the status
	 * 
	 * @param the
	 *            status
	 */
	public void setStatus(Long pStatus) {
		this.status = pStatus;
	}

	/**
	 * Gets the type
	 * 
	 * @returns the type
	 */
	@Column(name = "TYPE")
	public Long getType() {
		return this.type;
	}

	/**
	 * Sets the type
	 * 
	 * @param the
	 *            type
	 */
	public void setType(Long pType) {
		this.type = pType;
	}

	/**
	 * Gets the list of ClientContract
	 * 
	 * @returns the ClientContract List
	 */
	@ManyToOne
    @JoinTable(name = "CLIENT_CONTRACT",
        joinColumns = @JoinColumn(name="CONTRACT_ID"),
		inverseJoinColumns = @JoinColumn(name="CLIENT_ID")
    )
	public Client getClient() {
		return this.client;
	}

	/**
	 * Sets the clientContracts
	 * 
	 * @param the
	 *            clientContracts
	 */
	public void setClient(Client client) {
		this.client = client;
	}

	@Override
	public boolean equals(Object obj) {
		Contract otherContrat = (Contract) obj;
		EqualsBuilder equalsBuilder = new EqualsBuilder();
		equalsBuilder.append(getComment(), otherContrat.getComment());
		equalsBuilder.append(getStatus(), otherContrat.getStatus());
		equalsBuilder.append(getType(), otherContrat.getType());
		return equalsBuilder.isEquals();
	}

	@Override
	public int hashCode() {
		HashCodeBuilder hashCodeBuilder = new HashCodeBuilder();
		hashCodeBuilder.append(getComment());
		hashCodeBuilder.append(getStatus());
		hashCodeBuilder.append(getType());
		return hashCodeBuilder.toHashCode();
	}

	@Override
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		// buffer.append("Contrat");
		// buffer.append('\n');
		buffer.append("comment=").append(comment).append(',');
		buffer.append("status=").append(status).append(',');
		buffer.append("type=").append(type).append(',');
		return buffer.toString();
	}
}
